package com.blustc.detect.ane
{

	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	
	public class AudioDetectControl
	{
		public function AudioDetectControl()
		{
		}
		private static var extensionContext : ExtensionContext = null;
		private static var initialised : Boolean = false;
		//public static var onDlgAutoPurchaseInfoCancel:Signal0 = new Signal0();
	

		private static function init() : void
		{
			if ( !initialised )
			{
				initialised = true;
				extensionContext = ExtensionContext.createExtensionContext( "com.blustc.detect.ane", null );
				if(extensionContext){
					_isSupported = true;
					extensionContext.addEventListener( StatusEvent.STATUS, handleStatusEvent );
				}else {
					trace("not supported");
				}
				
			}
		}
		public static var _isSupported:Boolean;
		public static function get isSupported():Boolean {
			return _isSupported;
		}
		
		public static function initLIB():void {
			init();
			if(_isSupported){
				extensionContext.call(NativeMethods.LIBInit);
			}
		}
		
		public static function getVersion():String{
			return extensionContext.call(NativeMethods.getVersion) as String;
		}
		
		public static function startCapture():void{
			extensionContext.call(NativeMethods.startCapture);
		}
	
		private static function stopCapture():void{
			extensionContext.call(NativeMethods.stopCapture);
		}

		public static function dispose():void { 
			if(extensionContext.hasEventListener(StatusEvent.STATUS)){
				extensionContext.removeEventListener( StatusEvent.STATUS, handleStatusEvent );
			}
			extensionContext.dispose();
		}
		private static function handleStatusEvent( event : StatusEvent ) : void
		{
			switch( event.level )
			{
				case InternalMessages.onStartCaptureComplete :
					//onDlgAutoPurchaseInfoCancel.dispatch();
					break;
				case InternalMessages.onStopCaptureComplete :
					//onDlgError.dispatch();
					break;
				case InternalMessages.onJackInserted :
					//onDlgError.dispatch();
					break;
				case InternalMessages.onJackRemoved :
					//onDlgError.dispatch();
					break;
				case InternalMessages.onDataReceived :
					//onDlgError.dispatch();
					break;
				case InternalMessages.onErrorReceived :
					//onDlgError.dispatch();
					break;
			}
		}
	}
}